package lanqiao;

import java.util.Scanner;

public class 特别数的和 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        long sum = 0;
        for (int i = 1; i <=a; i++) {
            int b = i;
            while (b!=0){
               if (b%10==2 || b%10==0 || b%10==1 || b%10==9){
                   sum+=i;
                   break;
               }
               b=b/10;
            }
        }
        System.out.println(sum);
    }
}
